#pragma once


typedef struct
{
	WORD	wStart;
	WORD	wEnd;
} PIXEL_DATA, *PPIXEL_DATA;

#define	UM_PIXEL_DATA	(WM_USER + 0x100)


// CHistogramLCtrl

class CHistogramLCtrl : public CStatic
{
	DECLARE_DYNAMIC(CHistogramLCtrl)

public:
	CHistogramLCtrl();
	virtual ~CHistogramLCtrl();

	enum {
		IMG_SIZE=1600,
		BUF_SIZE=6500,	//1600*4 + 100
	};

	CRect		m_rect;
	BYTE		m_bThreshold;
	WORD		m_wXStart;
	WORD		m_wXEnd;
	BYTE		m_bMinWidth;
	BYTE		m_bAverageLight;

	BYTE		m_ImgBuf[BUF_SIZE];
	PBYTE		m_pImgBuf;
	PBYTE		m_pImgMax;
	PBYTE		m_pThdBuf;
	PBYTE		m_pThdMin;
	CArray<PIXEL_DATA,PIXEL_DATA>	m_aryTouch;
	BYTE		m_bCurrentLight;

	void setYCenter(int nYCenter);
	void setThreshold(BYTE bThreshold);
	void setXStart(WORD wXStart);
	void setXEnd(WORD wXEnd);
	void setMinWidth(BYTE bMinWidth);
	void setAverageLight(BYTE bAverageLight);

	void setData(DWORD dwPos, BYTE bLen, BYTE *pData);
	void makeImage(void);
	void drawImage(CDC *pDC);
	void drawData(DWORD dwSize);
	void clear(void);

protected:
	DECLARE_MESSAGE_MAP()
	virtual void PreSubclassWindow();
public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
};
